ImageGear Professional DLL for Windows
Developing the Application

Before completing the steps in this section, complete the following setup:

  1. If you are using a Deployment (Runtime) license, you must add the license initialization code: CIGSampleApp::InitInstance() in the IGSample application (IGSample.cpp). This is not necessary if you are using an Evaluation or Development (Toolkit) license.
    C++
    Copy Code
    BOOL CIGSampleApp::InitInstance()
    {
            // ...
           
            AfxEnableControlContainer();
     
            // Standard initialization
            // If you are not using these features and wish to reduce the size
            // of your final executable, you should remove from the following
            // the specific initialization routines you do not need.
     
            /*
            To unlock the toolkit for deployment you must call the
            IG_lic_solution_name_set, IG_lic_solution_key_set() and possibly the
            IG_lic_OEM_license_key_set() functions.
            See Licensing section in ImageGear User Manual for more details.
            */
            // ...
           
            return TRUE;
    }
    
  2. We will now add "Zoom In" and "Zoom Out" options under the application's View menu. To do this, go to View -> Resource View in the IDE menu. When the Resource View window displays, expand the Menu folder. Open IDR_MAINFRAME. Drop down the View option and add two items: Zoom In and Zoom Out. For this tutorial, the ID's of these two items are ID_ZIN and ID_ZOUT respectively. So right click each item, select Properties, and then change their ID fields to ID_ZIN and ID_ZOUT respectively.
  3. Next go to the Solution Explorer and view the header files. Open the IGSampleDoc.h file, and add the following statement:
    C++
    Copy Code
    #include "gear.h"
    

    This provides access to the ImageGear functions for use in our application.

  4. Also in the IGSampleDoc.h file, add the following declaration to the public attributes section of the code:
    C++
    Copy Code
    HIGEAR hIGear;
    

    This declares an ImageGear handle that will be used to hold the loaded image, which will be passed to the different ImageGear functions that are called.

  5. Next we will add code to the IGSampleDoc.cpp constructor and destructor functions. Open the IGSampleDoc.cpp file. Add the following code to the CIGSampleDoc::CIGSampleDoc() function:
    C++
    Copy Code
    hIGear = (HIGEAR)NULL;
    

    Then add the following code to the CIGSampleDoc::~CIGSampleDoc() function:

    C++
    Copy Code
    if( IG_image_is_valid( hIGear ) )
    IG_image_delete( hIGear );
    

    The code above utilizes:

    IG_image_is_valid()

    Called to determine if the HIGEAR variable hIGear contains a handle of a valid ImageGear image.

    IG_image_delete()

    Removes the HIGEAR handle of hIGear, and frees the memory of the associated HIGEAR structure. This function also frees the memory associated with the image's DIB, if ImageGear allocated the DIB memory. If ImageGear did not allocate the DIB memory, the DIB continues to exist, and it is the responsibility of your application to free this memory when done with it.

  6. Also in IGSampleDoc.cpp, we will use the Class View to add the virtual function OnOpenDocument. Go to View -> Class View in the IDE menu. Right click the CIGSampleDoc item in the tree and choose Properties. In the Properties window, select the button for overrides (second from the right). Scroll down and select OnOpenDocument. Click the down arrow for the combo box and choose '<Add> OnOpenDocument'. Add the following code into the function in place of the TODO comment:
    C++
    Copy Code
    if( IG_load_file( CT2A(lpszPathName), &hIGear )==0 ) return TRUE;
    else
    {
            //ErrorReport
            return FALSE;
    }
    

    The code above utilizes:

    IG_load_file()

    Loads the specified file into the HIGEAR.

    Note the use of the CT2A macro, which converts lpszPathName into an ANSI string so it can be passed to IG_load_file.

  7. Using the same Class View, right click CIGSampleDoc and choose Add->Add Function. In the Add Member Function Wizard, set the return type to AT_ERRCOUNT and function name to "dsplZoomSet" and add the following parameters:

    Type

    Name

    CView *

    v

    AT_MODE

    nZoomMode

    DOUBLE

    dHZoom

    DOUBLE

    dVZoom

    The Function signature should now look like this:

    C++
    Copy Code
    AT_ERRCOUNT dsplZoomSet(CView * v, AT_MODE nZoomMode, double
    dHZoom, double dVZoom)
    

    Click Finish to add the function.

    Next insert code under the member function in IGSampleDoc.cpp so that the final code looks like the following:

    C++
    Copy Code
    AT_ERRCOUNT CIGSampleDoc::dsplZoomSet(CView * v, AT_MODE
    nZoomMode, double dHZoom, double dVZoom)
    {
            DWORD dwGrpID=0;  
            AT_ERRCOUNT nErrCount;  
            nErrCount = IG_dspl_zoom_set( hIGear, dwGrpID, nZoomMode, dHZoom, dVZoom );  
    
            if( nErrCount!=NULL )  
            {  
                   //ErrorReport  
            }  
            return nErrCount;  
    }
    
  8. Now add two other member functions (dsplZoomGet, DrawImage) using the same process as in the previous step and matching their function declarations:
    C++
    Copy Code
    AT_ERRCOUNT CIGSampleDoc::dsplZoomGet(CView *v, LPAT_MODE
    lpnZoomMode, LPDOUBLE lpdHZoom, LPDOUBLE lpdVZoom)
    {
            DWORD dwGrpID=0;
            AT_ERRCOUNT nErrCount;
    
            nErrCount = IG_dspl_zoom_get( hIGear, dwGrpID, v->GetSafeHwnd(), lpnZoomMode, lpdHZoom, lpdVZoom );
    
            if( nErrCount!=NULL )
            {
                   //ErrorReport
            }
           
            return nErrCount;
    }
    
    void CIGSampleDoc::DrawImage( CView *v, CDC *dc, CPrintInfo
    *pInfo )
    {
            if( IG_image_is_valid( hIGear ) )
            {
                   DWORD dwGrpID=0;
                   POINT p;
                   SIZE s;
                   DWORD nMapMode;
                   AT_RECTANGLE Viewport;
                   AT_RECTANGLE Window;
    
                   /* get current mapping parameters */
                   nMapMode = ::GetMapMode( dc->m_hDC );
                   ::GetViewportOrgEx( dc->m_hDC, &p );
                   Viewport.x = p.x;
                   Viewport.y = p.y;
                   ::GetViewportExtEx( dc->m_hDC, &s );
                   Viewport.width = s.cx;
                   Viewport.height = s.cy;
                   ::GetWindowOrgEx( dc->m_hDC, &p );
                   Window.x = p.x;
                   Window.y = p.y;
                   ::GetWindowExtEx( dc->m_hDC, &s );
                   Window.width = s.cx;
                   Window.height = s.cy;
    
                   IG_dspl_mapmode_set( hIGear, dwGrpID, nMapMode, &Viewport,
                   &Window );
                   IG_dspl_image_draw( hIGear, dwGrpID, v->GetSafeHwnd(), dc->GetSafeHdc(), NULL );
            }
    }
    

    The code for these member functions includes:

    IG_dspl_mapmode_set()

    Sets the current map mode and logical coordinate system.

    IG_dspl_image_draw()

    Draws an image onto a destination device context.

    IG_dspl_zoom_set()

    Sets the zoom value.

    IG_dspl_zoom_get()

    Gets the current zoom value.

  9. Now we need to add code to IGSampleView.cpp for handling the menu events. Start off by finding the OnDraw functions. Remove the comments around pDC in the function declaration line so the function starts like this:
    C++
    Copy Code
    void CIGSampleView::OnDraw(CDC* pDC)
    

    Then add the following code to the OnDraw function:

    C++
    Copy Code
    pDoc->DrawImage( this, pDC, NULL );
    

    This calls the DrawImage function defined in IGSampleDoc.cpp and ensures that the image will be properly drawn when the window is redrawn.

  10. Next we need to add handles for ID_ZIN and ID_ZOUT. Using the ClassView, select CIGSampleView class and bring up the properties for it. In the properties view select the lightning bolt icon for Events. Scroll down and expand both the ID_ZIN and ID_ZOUT events. Click the down arrow for the combo box of the COMMAND field for each and choose to "<Add> OnZin" and "<Add> OnZout". Then insert the following code into the OnZin() function:
    C++
    Copy Code
    DOUBLE dHZoom, dVZoom;
    CIGSampleDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    
    pDoc->dsplZoomGet( this, NULL, &dHZoom, &dVZoom );
    dHZoom *= 1.25;
    dVZoom *= 1.25;
    pDoc->dsplZoomSet( this,
    IG_DSPL_ZOOM_H_FIXED|IG_DSPL_ZOOM_V_FIXED, dHZoom, dVZoom );
    
    InvalidateRect( NULL, FALSE ); //force redraw       
    UpdateWindow();  
    

    The above code zooms the image to 125 percent, or 5/4ths, of its size (zoom in by 25 percent).

    Finally, insert the following code into the OnZout() function:

    C++
    Copy Code
    DOUBLE dHZoom, dVZoom;
    CIGSampleDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    
    pDoc->dsplZoomGet( this, NULL, &dHZoom, &dVZoom );
    dHZoom /= 1.25;
    dVZoom /= 1.25;
    pDoc->dsplZoomSet( this,
    IG_DSPL_ZOOM_H_FIXED|IG_DSPL_ZOOM_V_FIXED, dHZoom, dVZoom );
    
    InvalidateRect( NULL, FALSE ); //force redraw
    UpdateWindow();  
    

    The above code zooms "out", decreasing the image to 4/5ths of its size, thereby canceling the effect of the zoom in above.

 

 


©2015. Accusoft Corporation. All Rights Reserved.

Send Feedback